package com.android.lovely.ui.dialog

import android.os.Build
import android.util.Log
import android.widget.NumberPicker
import androidx.fragment.app.activityViewModels
import com.android.lovely.R
import com.android.lovely.databinding.DialogImageCreateBinding
import com.android.lovely.databinding.DialogTransTimeBinding
import com.android.lovely.framework.BaseDialogFragment
import com.android.lovely.ui.viewmodel.TransViewModel
import com.android.lovely.ui.viewmodel.WorkCreateViewModel
import com.android.lovely.ui.viewmodel.WorkTaskViewModel
import com.kotlin.extensions.view.ViewExt.clickable
import okhttp3.internal.platform.android.AndroidLogHandler.setFormatter

/**
 *
 * @author why
 * @date 2025/3/13 18:55
 */
class CreateImageTypeDialog : BaseDialogFragment<DialogImageCreateBinding>() {
    val viewModel by activityViewModels<WorkTaskViewModel>()

    var trans = 0


    private val roleTabs by lazy {
        arrayOf(getString(R.string.all), getString(R.string.passed), getString(R.string.checking), getString(R.string.failed))
    }

    override fun initializeViews() {
        trans = when(viewModel.status){
            1 -> 1
            0 -> 2
            null -> 0
            else -> 3
        }
        binding.tvTitle.text = getString(R.string.select_type)

        binding.mainWheelRight.apply {
            // 配置数值范围
            setDisplayedValues(roleTabs)
            setWrapSelectorWheel(false)
            minValue = 0
            maxValue = roleTabs.size - 1
            hideNumberPickerDivider()
            value = trans // 默认值
            scrollBarSize = 0
            setFormatter { value ->
                value.toString().padStart(2, '0')
            }
// 监听数值变化
            setOnValueChangedListener { _, oldVal, newVal ->
                Log.d("Picker", "值变化：$oldVal -> $newVal")
                trans = newVal
            }
        }

        binding.ivClose.clickable {
            dismissAllowingStateLoss()
        }
        binding.confirmBtn.clickable {
            viewModel.update(trans)
            dismissAllowingStateLoss()
        }
    }

    override fun isBottom(): Boolean {
        return true
    }

}

